package com.deepexi.sample.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class RedisController {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private ValueOperations<String, String> valueOperations;

    @ResponseBody
    @RequestMapping(value = "redis")
    public String redis() {
        // String val = redisTemplate.opsForValue().get("testkey").toString();
        return valueOperations.get("testkey").toString();
    }

    @RequestMapping(value = "redisw/{val}")
    public String redisWrite(@PathVariable(name = "val") String val) {
        redisTemplate.opsForValue().set("testkey", val);
        return "ok";
    }
}
